var util = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    unionid: '',
    openId: '',
    needDelId: 0,
    resumeList: [],
    show: false,
    actions: [{
      name: '删除',
      color: '#ff0000',
      type: 'del'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      unionid: wx.getStorageSync('unionid'),
      openId: wx.getStorageSync('openid'),
    });
    console.log("============", this.data.unionid);
    this.getResumeList();
  },
  del: function (event) {
    this.setData({
      show: true,
      needDelId: event.target.dataset.id
    });
  },
  cancel: function () {
    this.setData({
      show: false,
      needDelId: 0
    });
  },
  clickOverlay: function () {
    this.setData({
      show: false
    });
  },
  select: function (options) {
    var that = this;
    var operation = options.detail.type
    if ('del' == operation) {
      console.log("刪除")
    }
    util.post(app.api.deleResume, {
      'unionid': this.data.unionid,
      'id': this.data.needDelId
    }, function (res) {
      wx.showToast({
        title: '删除成功',
      })
      that.setData({
        show: false
      })
      that.onLoad();
    })
  },

  getResumeList() {
    var that = this;
    util.post(app.api.getResumeList, {
      'unionid': this.data.unionid,
      'openId': this.data.openId
    }, function (res) {
      let result = res.data;
      that.setData({
        resumeList: result
      })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  onClose() {
    this.setData({
      show: false
    });
  },
  up(){
    let that = this
    wx.showModal({
      title: '提示',
      content: '打开微信选择要上传的简历',
      success (res) {
        if (res.confirm) {
          that.upResume()
        } else if (res.cancel) {
          wx.hideToast()
        }
      }
    })
  },
  upResume: function(){
    var that = this;
    var unionid= this.data.unionid;
    wx.chooseMessageFile({
      count: 1,
      type: 'file',
      success(res) {
        var filename = res.tempFiles[0].name
        let uri = 'https://www.tiaonali.com/tnl-wxapp/user/uploadResume';
        //http://10.71.49.10:8000
        //https://www.tiaonali.com
        wx.uploadFile({
          url: uri,
          filePath: res.tempFiles[0].path,
          name: 'file',
          formData: {
            "unionid":unionid,
            "fileName":filename,
          },
          success(res) {
            if(res.statusCode == 200){
              that.onLoad();
            }
          }
        })
      }
    });
  },
  onSelect(event) {
    console.log(event.detail);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})